//
//  FoundViewController.m
//  Yiqidianyin
//
//  Created by apple on 15/8/9.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "FoundViewController.h"
#import "MBProgressHUD.h"


@interface FoundViewController ()<UIWebViewDelegate,MBProgressHUDDelegate>

{
    MBProgressHUD *HUD;
    long long expectedLength;
    long long currentLength;
}


@property (weak, nonatomic) IBOutlet UIWebView *WebView;

@end

@implementation FoundViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self getweb];
    
    [self.WebView reload];
}

- (void)viewDidUnload
{
    [self getweb];
    
    [self.WebView stopLoading];
    

}


-(void)getweb
{
     self.automaticallyAdjustsScrollViewInsets=NO;
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
//    NSURL *url = [NSURL URLWithString:@"http://www.17dianying.cn/v3/m/index.html/#/discovery"];
    
    NSURL *url = [NSURL URLWithString:@"http://www.17dianying.cn/v3/discovery/index.html"];
    
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    [self.WebView loadRequest:req];
    self.WebView.delegate = self;
    
}

#pragma mark - 视图将要出现
- (void)viewWillAppear:(BOOL)animated
{
    //导航栏背景
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bargound.png"] forBarMetrics:UIBarMetricsDefault];
    
    //导航栏底部线
    self.navigationController.navigationBar.shadowImage =[UIImage imageNamed:@"nav_bargound.png"];
}
#pragma mark - 视图将要消失
- (void)viewWillDisappear:(BOOL)animated
{
    //导航栏背景
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    
    //导航栏底部线
    self.navigationController.navigationBar.shadowImage =[UIImage imageNamed:@""];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    
    HUD.dimBackground = YES;
    
    
    HUD.delegate = self;
    
    
    [HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [HUD hide:YES];

}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    NSLog(@"加载网页失败:%@",error.localizedDescription);
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)myTask {
    // Do something usefull in here instead of sleeping ...
    sleep(6);
}


@end
